/**
 * @Description 打印接口信息
 *
 * @author author @CreateDate 2020-05-19 16:16:26 @UpdateDate 2020-05-19 16:16:26
 */
package com.ht.managermentserver.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;

import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;

@Configuration
@Slf4j
public class SysPrintConfig {

  @Autowired Environment environment;

  @Value("${spring.profiles.active}")
  private List<String> env;

  @Value("${server.port}")
  private Integer port;

  @Bean
  public void printSwaggerUrl() {

    final Profiles profiles = Profiles.of("dev", "test");
    final Boolean dev = environment.acceptsProfiles(profiles);
    if (dev) {

      InetAddress localHost = null;
      try {
        localHost = Inet4Address.getLocalHost();
      } catch (final UnknownHostException e) {
        log.error(e.getMessage(), e);
      }
      final String ip = localHost.getHostAddress();
      final String port = environment.getProperty("server.port");

      // log.info(String.format("[swagger-url]:http://localhost:%s/swagger-ui.html", port));
      log.info(String.format("[swagger-url]:http://%s:%s/swagger-ui.html", ip, port));
      log.info(String.format("[页面地址]:    http://%s:%s/ui/", ip, port));
      log.info(String.format("[接口地址]:    http://%s:%s/api/*", ip, port));
    }
  }
}
